package transactions;

import java.sql.Connection;
import java.sql.SQLException;

import tables.Badge;
/**
 *Modifier l'etat d'un badge
 *
 */
public class ModifierBadgeEtat implements transactions.Transaction_SUPER {
	
    private java.sql.Connection conn;
    private int numBadge;
    private String etat;
    
    public ModifierBadgeEtat(java.sql.Connection pConn, int pNumBadge, String pEtat){
            this.conn = pConn;
            this.numBadge = pNumBadge;
            this.etat = pEtat.toUpperCase();
    }
    
    public void query() throws SQLException{
            try {
            	conn.setAutoCommit(false);    
            	conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                java.sql.Statement stat = conn.createStatement();
                
                //update de l'etat du badge
                String cmd = new Badge(numBadge,etat).update();
                stat.executeUpdate(cmd);
                conn.commit();
            } catch (SQLException e) {
                System.out.println("Erreur lors de l'insertion");
                conn.rollback();
                e.printStackTrace();
            }
            
    }
	
}
